package com.unsiv.blplayer.playtools;

import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collections;

public class OIDConfig {
	// 图文码值规划
	// 码值范围 功能
	// 有声图书 1,000,001~1,000,200 (大型MP3)
	// SoftKey 1,000,201~1,000,400
	// MP3 1,000,401~1,000,800
	// REC 1,000,801~1,011,000
	// 联网码 1,011,001~1,016,000
	// BookName 1,016,001~1,026,000
	// 书码 1,026,001~1,048,575
	public static final Integer BigMP3Min = 1000001;// 有声图书最小值(大型MP3)
	public static final Integer BigMP3Max = 1000200;// 有声图书最大值(大型MP3)

	public static final Integer SoftKeyMin = 1000201;// SoftKey最小值
	public static final Integer SoftKeyMax = 1000400;// SoftKey最大值

	public static final Integer Mp3Min = 1000201;// Mp3最小值
	public static final Integer Mp3Max = 1000800;// Mp3最大值

	public static final Integer RecMin = 1000801;// REC最小值
	public static final Integer RecMax = 1011000;// REC最大值

	public static final Integer NetWorkingMin = 1011001;// 联网码最小值
	public static final Integer NetWorkingMax = 1016000;// 联网码最大值

	public static final Integer BookNameMin = 1016001;// BookName最小值
	public static final Integer BookNameMax = 1026000;// BookName最大值

	public static final Integer BookcodeMin = 1026001;// 书码最小值
	public static final Integer BookcodeMax = 1048575;// 书码最大值

	public static final Integer PointBookMin = 0;// 书码最小值
	public static final Integer PointBookMax = 1040000;// 书码最大值

	public static final Integer VolumeAdd = 1000233; // 音量增加
	public static final Integer VolumeLower = 1000234;// 音量降低

	public static final Integer PassBoxMin = 1000236;// 密码箱最小值
	public static final Integer PassBoxMax = 1000248;// 密码箱最大值

	public static final Integer FileSynchroMin = 1000236;// 文件同步最小值
	public static final Integer FileSynchroMax = 1000248;// 文件同步最大值

	// / <summary>
	// / 取最后四个字节
	// / </summary>
	// / <param name="recvBytes"></param>
	// / <returns></returns>
	public static Integer GetOIDCode(byte[] recvBytes) {
		Integer oidCode = 0;
		byte[] oidBytes = new byte[4];
		System.arraycopy(recvBytes, recvBytes.length - 6, oidBytes, 0, 4);
		Collections.reverse(Arrays.asList(oidBytes));
		ByteBuffer bb = ByteBuffer.wrap(oidBytes);
		oidCode = bb.getInt();
		return oidCode;
	}

	// / <returns></returns>
	public static String GetOIDCode(byte[] recvBytes, String workType) {
		// workType = "+ID";
		Integer odiCode = 0;
		int strLen = 0;
		String recvStr = recvBytes.toString();
		for (int i = 0; i < recvStr.length(); i++) {
			if (Character.isLetter(recvStr.charAt(i))) {
				continue;
			} else {
				strLen = i;
				break;
			}
		}
		byte[] oidBytes = new byte[4];
		System.arraycopy(recvBytes, strLen, oidBytes, 0, 4);
		ByteBuffer bb = ByteBuffer.wrap(oidBytes);
		odiCode = bb.getInt();
		String recvCode = recvStr.substring(0, strLen) + odiCode;

		return "+ID"; // out String workType
	}
}